/*
 * [legal notice here]
 */
package com.hexacta.hrs.domain.exchange;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.vectrics.common.db.AbstractRecordObject;

/**
 * TODO insert class description here.
 * 
 * Created on 16/08/2012
 * 
 * @author GVILLA
 * 
 */
public class Exchange extends AbstractRecordObject {

    private Currency currency;

    private Set<ExchangeItem> exchanges;

    public Exchange() {
        exchanges = new HashSet<ExchangeItem>();
    }

    /**
     * GETTERS AND SETTERS
     */

    /**
     * @param exchanges
     *            the exchanges to set
     */
    public void setExchanges(final Set<ExchangeItem> exchanges) {
        this.exchanges = exchanges;
    }

    /**
     * @param currency
     *            the currency to set
     */
    public void setCurrency(final Currency currency) {
        this.currency = currency;
    }

    /**
     * @return the exchanges
     */
    public Set<ExchangeItem> getExchanges() {
        return exchanges;
    }

    /**
     * @return the currency
     */
    public Currency getCurrency() {
        return currency;
    }

    /**
     * @param selectedExchangeItemId
     * @return
     */
    public ExchangeItem findItem(final Long selectedExchangeItemId) {
        for (ExchangeItem item : exchanges) {
            if (item.getId().equals(selectedExchangeItemId))
                return item;
        }

        return null;
    }

    /**
     * @param selectedExchangeItemId
     * @return
     */
    public void removeItem(final Long selectedExchangeItemId) {
        Iterator<ExchangeItem> iter = exchanges.iterator();
        while (iter.hasNext()) {
            ExchangeItem next = iter.next();
            if (next.getId().equals(selectedExchangeItemId)) {
                iter.remove();
            }
        }
    }
}
